package faker

import (
	"encoding/json"
	"math/rand"
	"time"
)

type Streets struct {
	Code         string `json:"code"`
	Name         string `json:"name"`
	AreaCode     string `json:"areaCode"`
	CityCode     string `json:"cityCode"`
	ProvinceCode string `json:"provinceCode"`
}

func ReadStreets() (file []*Streets, err error) {

	//if content, err = ioutil.ReadFile(StreetsStr); err != nil {
	//	return file, err
	//}

	if err = json.Unmarshal([]byte(StreetsStr), &file); err != nil {
		return
	}

	return
}

func Address() string {
	var (
		addresses []*Streets
		err error
	)

	if addresses, err = ReadStreets(); err != nil {
		panic(err)
	}
	rand.Seed(time.Now().UnixNano())
	return addresses[rand.Intn(len(addresses))].Name
}


